﻿using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using WebApiTwo.entity;
using WebApiTwo.IService;
using WebApiTwo.Model;

namespace WebApiTwo.Service
{
    public class StudentService : IStudentService
    {
        private readonly AppDbContext db;
        private readonly ILogger<StudentService> logger;
        private readonly IMapper mapper;

        public StudentService(AppDbContext db, ILogger<StudentService> logger, IMapper mapper) {
            this.db = db;
            this.logger = logger;
            this.mapper = mapper;
        }
        public async Task<IEnumerable<StudentRes>> GetAllStudent()
        {
            logger.LogError("查询所有");
            var student = await db.Students.ProjectTo<StudentRes>(mapper.ConfigurationProvider).ToListAsync();
            return student;
        }
    }
}
